<?php

$showurl = @file_get_contents('http://epguides.com/'.$getshow.'/');

if ($showurl) {

	//Get epguides.com Title
	preg_match('#<title>.+\(#iU', $showurl, $title);
	$showname =  trim(substr($title[0], 7, -2),  " :\n\t\r!");

	//Parse and split up epguides content
	$subject = $showurl;


	$pattern = '#([0-9]{1,3}\.)(\s+)('.$season.'\-[\s]?'.$episode_nr.')(\s+)([0-9a-zA-Z\s-]+)(\s+)([0-9]{1,2}[\s]?[a-zA-Z]{3}[\s]?[0-9]{2})(\s+)(<a target="(_blank|visit)" href="http://www.tv.com[\D\d\s]+>)([\D\d\s]+</a>)#iU';


	preg_match_all($pattern, $subject, $matches);

   	$numbers = $matches[1];
   	$episodes = $matches[3];
   	$urls = $matches[9];
   	$titles = $matches[11];
   	$arrayShows = array();

   	for( $x = 0; $x < count($numbers); $x++ ){
         $number = array('number' => $numbers[$x], 'episode' => $episodes[$x], 'url' => $urls[$x], 'title' => $titles[$x]);
         array_push($arrayShows, $number);
    }

	if ($episode_nr <= $number) {

		foreach($arrayShows as $value) {

			$value['url'] = str_replace(" &amp", "&", $value['url']);
			$value['url'] = str_replace('<a target="_blank" href="', '', $value['url']);
			$value['url'] = str_replace('<a target="visit" href="', '', $value['url']);
			$value['url'] = str_replace('">', '', $value['url']);
			$url = $value['url'];
   			$value['title'] = str_replace(" &amp", "&", $value['title']);
			$value['title'] = str_replace("</a>", "", $value['title']);
			$title = $value['title'];
			$episodenumber = trim(substr($value['episode'],-2, 2), " ");
			$episode = $episodenumber;
		
			include("get_summary.php");
	
		}
	}
	else {
		$title = "";
	}

}
?>